package xju_9_10.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import xju_9_10.dao.StudentDao;
import xju_9_10.entity.Stu;
import xju_9_10.entity.Student;
import xju_9_10.service.UserService;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

@Service
@Transactional
public class UserServiceImpl implements UserService {
    // 调用持久层
    @Autowired
    private StudentDao studentDao;

    @Override
    @Transactional(readOnly = false,timeout = 2,rollbackFor = Exception.class)
    public void save(Stu student) throws FileNotFoundException {
        System.out.println("save");
//        try {
//            Thread.sleep(3000);
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }
        studentDao.save(student);
        // 非运行时异常
        new FileInputStream("xx");

//        int a = 10/0;
    }

    @Override
    public void update() {
        System.out.println("update");
    }

    @Override
    public void delete() {
        System.out.println("delete");
    }

    @Override
    public void select() {
        System.out.println("select");
    }
}
